//
//  NVideoViewController.m
//  SampleApp2
//
//  Created by GXHC on 2023/6/30.
//

#import "NVideoViewController.h"
#import "NVideoSectionController.h"
#import "../../RecommendController/Model/GTListLoader.h"
@interface NVideoViewController ()<IGListAdapterDataSource,UIScrollViewDelegate>

@property(nonatomic, strong, readwrite)UICollectionView *collectionView;
@property(nonatomic, strong, readwrite)IGListAdapter *listAdapter;
@property(nonatomic, strong, readwrite)GTListLoader *listLoader;
@property(nonatomic, strong, readwrite)NSArray *dataArray;

@end

@implementation NVideoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
	self.listLoader = [[GTListLoader alloc]init];
	[self.view addSubview:({
		self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,  self.view.frame.size.height+80) collectionViewLayout:[UICollectionViewFlowLayout new]];
		self.collectionView;
	})];
	
	self.listAdapter = [[IGListAdapter alloc]initWithUpdater:[IGListAdapterUpdater new] viewController:self workingRangeSize:0];
	self.listAdapter.dataSource = self;
	self.listAdapter.scrollViewDelegate = self;
	self.listAdapter.collectionView = self.collectionView;
	
	__weak typeof(self)wself = self;
	[self.listLoader loadListDataWithFinishBlck:^(BOOL success, NSArray<GTListItem *> *dataArray) {
		__strong typeof(wself) strongSelf = wself;
		strongSelf.dataArray = dataArray;
		[strongSelf.listAdapter reloadDataWithCompletion:^(BOOL finished) {
			NSLog(@"");
		}];
	}];
	
}


#pragma mark - IGListAdapterDataSource

- (NSArray<id <IGListDiffable>> *)objectsForListAdapter:(IGListAdapter *)listAdapter{
	return self.dataArray;
}

- (IGListSectionController *)listAdapter:(IGListAdapter *)listAdapter sectionControllerForObject:(id)object{
	return [NVideoSectionController new];
}

- (nullable UIView *)emptyViewForListAdapter:(IGListAdapter *)listAdapter{
	return nil;
}

@end
